# bacon
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../func
. ../build.conf

URL=http://www.basic-converter.org/stable/
PKG=bacon
VER=3.1
COMP=tar.gz
DESC="BaCon - Basic to C converter"
DEPS=
CAT=Utility
DESKTOP=bacongui.desktop
BUILD=
CWD=$(pwd)
[ -z "$MWD" ] && MWD=$(dirname $CWD)	
[ -z "$BUILD" ] && BUILD=$DEF_BUILD

ARCH=`uname -m`
case $ARCH in
 *64) LIBDIR=lib64 ;;
 *) LIBDIR=lib ;;
esac

build() {
	# since not X compiling forget build triplet
	cd ${PKG}-${VER}
	# nasty hack for tahr
	#sed -i 's% || -z `which pwd`%%' bacon.sh
	./configure --prefix=/usr \
				--localstatedir=/var \
				--sysconfdir=/etc \
				--libdir=/usr/${LIBDIR}
	[ "$?" -eq 0 ] || build_fail $PKG
	make
	# bacon doesn't support DESTDIR or new2dir, plus its _DEV only
	[ "$?" -eq 0 ] || build_fail $PKG
	strip --strip-unneeded build/*
	install -d -m 0755 $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/{bin,$LIBDIR}
	install -d -m 0755 $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/man/man1
	install -d -m 0755 $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/pixmaps
	install -m 0755 build/{bacon,bacongui} $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/bin
	install -m 0755 bacon.sh $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/bin
	install -m 0755 build/libbacon.a $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/$LIBDIR
	install -m 0644 bacon.1 $CWD/${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/man/man1
	cd -
}
	
package() {
	# add this recipe #_DEV is special for bacon only
	install -d -m 0755 ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/doc
	install -m 0644 BaCon.png ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/pixmaps
	cat ${PKG}.petbuild > ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/doc/$PKG-build-recipe
	if [ "$DESKTOP" ];then
		install -d -m 0755 ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/applications
		cat $DESKTOP > ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/usr/share/applications/$DESKTOP
	fi
	[ -f ./pinstall.sh ] && install -m 0755 pinstall.sh ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/
	[ -f ./puninstall.sh ] && install -m 0755 puninstall.sh ./${PKG}_DEV-${VER}-${ARCH}_${BUILD}/
	for p in `ls|grep "\-${ARCH}"|grep -v "files$"` ; do
		case $p in
#			*_DEV*) DESC="${PKG}_DEV development"; DEPS=+${PKG} ;;
			*_DOC*) DESC="${PKG}_DEV documentation"; DEPS=+${PKG} ;;
			*_NLS*) DESC="${PKG}_DEV locales"; DEPS=+${PKG} ;;
		esac	
		echo "packaging $p"	
		dir2pet -x -s -w="$DESC" -d="$DEPS" -c=$CAT -p=${p} 2>&1 >/dev/null
		rm -r $p
		mv ${p}.pet ../0pets_out
	done
	rm -r ${PKG}-${VER}
	rm *.files 2>/dev/null
	echo "done!"
}

# main
retrieve ${PKG}-${VER}.${COMP}
extract ${PKG}-${VER}.${COMP}
build
package	
